package com.tj.jinzao.activity;

import android.app.Activity;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.tj.jinzao.R;
import com.tj.jinzao.base.BaseActivity;
import com.tj.jinzao.callback.IUploadView;
import com.tj.jinzao.common.Constant;
import com.tj.jinzao.model.Case;
import com.tj.jinzao.model.Target;
import com.tj.jinzao.presenter.CasePresenter;
import com.tj.jinzao.utils.Utils;

import java.util.List;

import butterknife.BindView;
import butterknife.BindViews;

/**
 * 病历详情界面
 * Created by wjy on 2019/1/5.
 */
public class CaseDetailActivity extends BaseActivity implements IUploadView<List<Case>> {

    @BindViews({R.id.iv_card, R.id.iv_card_1, R.id.iv_card_2, R.id.iv_card_3, R.id.iv_card_4})
    List<ImageView> mCardView;
    @BindView(R.id.tv_name)
    TextView mNameView;
    @BindView(R.id.tv_date)
    TextView mDateView;

    private CasePresenter mPresenter;
    private long mId;//病历id

    @Override
    protected void setupView() {
        super.setupView();
        mId = getIntent().getLongExtra("id", 0);
        if (mId == 0) {
            finish();
            return;
        }
        mPresenter = new CasePresenter(this);
        mPresenter.getCaseById(mId);
        int width = Constant.SCREEN_WIDTH - Utils.dpToPx(32, getResources());
        int height = width * 190 / 335;
        for (int i=0;i<5;i++){
            LinearLayout.LayoutParams layoutParams=new LinearLayout.LayoutParams(width, height);
            layoutParams.topMargin=Utils.dpToPx(15, getResources());
            mCardView.get(i).setLayoutParams(layoutParams);
        }
    }

    @Override
    public int getLayoutResource() {
        return R.layout.activity_case_detail;
    }

    @Override
    protected int getLeftButtonResId() {
        return R.mipmap.ic_back;
    }

    @Override
    public Activity getContext() {
        return this;
    }

    @Override
    public void onRequestSuccess(List<Case> cases) {
        Case bean = cases.get(0);

        if (bean != null) {
            String url[]=bean.getImgurls().split(",");
            for (int i=0;i<url.length;i++){
                Log.w("数据接收",""+url[i]);
                mCardView.get(i).setVisibility(View.VISIBLE);
                Glide.with(this).load(Constant.IMAGE_PREFIX + url[i]).into(mCardView.get(i));
            }

            mNameView.setText(bean.getName());
            mDateView.setText(bean.getReportTime());
        }
    }

    @Override
    public void onRequestNoData(String message) {

    }

    @Override
    public void onRequestError(String error_message) {

    }

    @Override
    public void onUploadSuccess(String path, String url) {
    }

    @Override
    public void onCaseSuccess(List<Target> list) {

    }

    @Override
    public void onCaseFailed(String msg) {

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mPresenter != null) mPresenter.detachView();
    }
}
